﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Net.Mail;
namespace Guline.Web.CentralModels.Object
{
    public class SmtpConfig
    {
        [Key]
        public int ID { get; set; }
        public string SmtpHost { get; set; }
        public int SmtpPort { get; set; }
        public string SmtpUser { get; set; }
        public string SmtpPassword { get; set; }

        public bool sendMail(string emailReceive,string title, string Content)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient(this.SmtpHost);

                mail.From = new MailAddress(this.SmtpUser);
                mail.To.Add(emailReceive);
                mail.Subject = title;
                mail.Body = Content;

                SmtpServer.Port = this.SmtpPort;
                SmtpServer.Credentials = new System.Net.NetworkCredential(this.SmtpUser,this.SmtpPassword);
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
